<script>
	import {
		getStorage,
		removeStorage
	} from '@/util/auth.js';
	import {getWxLoginCode} from '@/util/user.js'
	export default {
		onLaunch: function() {
			uni.loadFontFace({
				source:'url("https://job-supermarket-1306862033.cos.ap-chengdu.myqcloud.com/uniapp/%E6%96%B9%E6%AD%A3%E6%B1%89%E7%9C%9F%E5%B9%BF%E6%A0%87%E7%AE%80%E4%BD%93.TTF")',
				family:'FangZhengHanZhenGuangBiaoJianTi',
				global:true,
			})
			//监听路由跳转
			let _this = this;
			uni.addInterceptor('navigateTo', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('redirectTo', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('reLaunch', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			uni.addInterceptor('switchTab', {
				invoke(e) {
					return _this.watchRouter(e);
				}
			})
			//自动登录
			if(!this.$store.getters.token){
				getWxLoginCode().then((code)=>{
					uni.showLoading({
						title:'加载中',
						mask:true,
					})
					this.$store.dispatch('user/getWxLoginCode',code)
				})
			}
			this.$store.dispatch('position/getPosition')
		},
		methods: {
			watchRouter(e) {
				let url = e.url;
				const index = url.indexOf('?');
				url = index == -1 ? url : url.slice(0, index);
				const hasToken = getStorage('token');
				const user = getStorage('user');
				const whiteList = ['/pages/index/index','/pages/mine/index','pages/release/index','/page_other/work/search','/page_other/work/conditions','/page_other/work_type_choose_list','/page_other/work/detail','/page_other/post/index','/page_other/post/detail'];
				if (user&&hasToken) {
					return true
				} else {
					if (whiteList.includes(url)) {
						return true
					} else {
						uni.showModal({
							title: '提示',
							content: '需要先登录！',
							cancelText: '先逛逛',
							confirmText: '去登录',
							success(res) {
								if (res.confirm) {
									uni.switchTab({
										url: '/pages/mine/index'
									})
								}
							}
						})
					}
				}
				return false;
			}
		},
	}
</script>

<style lang="scss">
	@import url("@/static/iconfont/iconfont.css");
	.FZHZGBJ{
		font-family: 'FangZhengHanZhenGuangBiaoJianTi';
	}
	button{
		padding: 0;
		background: none;
		line-height: normal !important;
	}
	button::after{
		border: none !important;
	}
	view,
	text,
	navigator,
	input,
	picker,
	button,
	scroll-view,
	textarea,
	image {
		box-sizing: border-box;
	}
	.block{
		position: relative;
	}

	.empty {
		text-align: center;
		color: #313131;
		font-size: 28rpx;
		margin: 30rpx 0;
	}

	page {
		min-height: calc(100vh - var(--window-bottom) - var(--window-top));
		background: #f8f8f8;
	}
	.page{
		width: 100%;
		min-height: calc(100vh - var(--window-bottom) - var(--window-top));
	}

	.input-placeholder {
		color: #686868;
		font-weight: normal;
	}
	.btn{
		width: 300rpx;
		height: 80rpx;
		border-radius: 20px;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.btn.normal{
		color: #fff;
		background: $orange-color;
	}
	.btn.cancel{
		color: $orange-color;
		background: #fff;
		border: 1px solid $orange-color;
	}
	.btn.disabled{
		color: #fff;
		background: #999;
		border: none;
	}
	
	image{
		display: block;
	}
</style>
